package com.frank.pipeline.service.core;

import com.frank.pipeline.codegen.entity.pipeline.tables.records.PipelineInfoRecord;
import com.frank.pipeline.domain.PipelineVo;
import com.frank.pipeline.repository.pipeline.PipelineInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jianweilin
 * @date 2017/11/7
 */
@Service
public class PipelineService {
    @Autowired
    private PipelineInfoRepository pipelineInfoRepository;

    public boolean isExist(Long pipelineNo){
        return pipelineInfoRepository.isExist(pipelineNo);
    }

    public void addPipelineInfo(PipelineVo pipelineVo){
        pipelineInfoRepository.addPipelineInfo(PipelineVo.transferToPipelineInfo(pipelineVo));
    }

    public PipelineVo getPipelineInfo(Long pipelineNo){
        List<PipelineInfoRecord> pipelineInfos = pipelineInfoRepository.getPipelineInfo(pipelineNo);
        return pipelineInfos.size()==0 ?  null : PipelineVo.transferToPipelineVo(pipelineInfos.get(0));
    }

    public List<PipelineVo> getPipelineList(){
        return pipelineInfoRepository.getPipelineList().stream()
                .map(info -> PipelineVo.transferToPipelineVo(info)).collect(Collectors.toList());
    }

    public void modify(PipelineVo pipelineVo){
        pipelineInfoRepository.modify(PipelineVo.transferToPipelineInfo(pipelineVo));
    }


}
